Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce mandatory session verification only for new logins #2811

Conversation

jmartinesp
Copy link
Contributor

Type of change

  • Feature
  • Bugfix
  • Technical
  • Other :

Content

  • Creates AppMigration base interface as a way to isolate migration logic, app migrations must implement this interface.
  • Creates AppMigration01 with the existing logs removal migration and AppMigration02 with the logic to allow existing sessions to skip verification.
  • Add DefaultSessionPreferencesStoreFactory.remove(sessionId) to allow a ephemeral session store access to exist outside the SessionScope for this new migration.

Motivation and context

Closes #2810.

Tests

Either log in using a previous version of the app and don't verify your device yet, or:

  • Log in normally without verifying.
  • Uncomment the code in MigrationPresenter to reset the migration version.
  • Re-run the app.

You should skip the verification flow.

Tested devices

  • Physical
  • Emulator
  • OS version(s): 14

Checklist

- Creates `AppMigration` base interface as a way to isolate migration logic, app migrations must implement this interface.
- Creates `AppMigration01` with the existing logs removal migration and `AppMigration02` with the logic to allow existing sessions to skip verification.
- Add `DefaultSessionPreferencesStoreFactory.remove(sessionId)` to allow a ephemeral session store access to exist outside the `SessionScope` for this new migration.
@jmartinesp jmartinesp requested a review from a team as a code owner May 7, 2024 09:44
@jmartinesp jmartinesp requested review from bmarty and removed request for a team May 7, 2024 09:44
Copy link

codecov bot commented May 7, 2024

Codecov Report

Attention: Patch coverage is 92.50000% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 73.45%. Comparing base (740571b) to head (fc6937d).
Report is 5 commits behind head on develop.

Files Patch % Lines
...mpl/store/DefaultSessionPreferencesStoreFactory.kt 0.00% 2 Missing ⚠️
...roid/features/migration/impl/MigrationPresenter.kt 80.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2811      +/-   ##
===========================================
+ Coverage    73.43%   73.45%   +0.02%     
===========================================
  Files         1523     1527       +4     
  Lines        36532    36564      +32     
  Branches      7042     7044       +2     
===========================================
+ Hits         26827    26858      +31     
  Misses        6026     6026              
- Partials      3679     3680       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

github-actions bot commented May 7, 2024

📱 Scan the QR code below to install the build (arm64 only) for this PR.
QR code
If you can't scan the QR code you can install the build via this link: https://i.diawi.com/DbkVpP

This also includes creating several abstractions.
Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. A few remarks.
(not tested yet, but will hopefully do later)

// migrationStore.setApplicationMigrationVersion(0)
// }

val orderedMigrations = migrations.sortedBy { it.order }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be moved as a Class member I think, and so migrations should not be a class member, to avoid any mistake.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean storing it as a property and making migrations just a constructor parameter?

@@ -68,6 +74,6 @@ class MigrationPresenter @Inject constructor(
companion object {
// Increment this value when you need to run the migration again, and
// add step in the LaunchedEffect above
const val MIGRATION_VERSION = 1
const val MIGRATION_VERSION = 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MIGRATION_VERSION should maybe remove, and use migrations.maxOf { it.order } instead, maybe, again, I think it will reduce the risk of error.

For instance, the new code never write MIGRATION_VERSION to the store as before:

migrationStore.setApplicationMigrationVersion(MIGRATION_VERSION)


package io.element.android.features.migration.impl.migrations

interface AppMigration {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be moved to the api module, so that any module may contribute to migrate their internal state. But maybe keep this for later.

- Make `orderedMigrations` a class property, `migrations` just a constructor parameter to avoid incorrect usages.
- Create `lastMigration` property too, use it instead of `MIGRATION_VERSION`.
Copy link

sonarcloud bot commented May 7, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

) : Presenter<MigrationState> {
private val orderedMigrations = migrations.sortedBy { it.order }
private val lastMigration: Int = orderedMigrations.lastOrNull()?.order ?: 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@jmartinesp jmartinesp added the Run-Maestro Starts a Maestro Cloud session to run integration tests label May 7, 2024
@github-actions github-actions bot removed the Run-Maestro Starts a Maestro Cloud session to run integration tests label May 7, 2024
@jmartinesp jmartinesp enabled auto-merge (squash) May 7, 2024 13:58
@jmartinesp jmartinesp merged commit 5c59f6c into develop May 7, 2024
19 checks passed
@jmartinesp jmartinesp deleted the fix/jme/2810-enforce-mandatory-verification-only-for-new-logins branch May 7, 2024 14:06
@bmarty
Copy link
Member

bmarty commented May 7, 2024

OK, I have done some test and it seems to work. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Task] Enforce mandatory verification only for new logins
2 participants